<template>
  <header>
    <div class="l-content">
      <el-button
        @click="handleMenu"
        plain
        icon="el-icon-menu"
        size="mini"
      ></el-button>
    </div>
    <div class="r-content">
      <el-dropdown tirgger="click" size="mini" @command="handleCommand">
        <span>
          <img class="user" :src="userImg" />
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="goTo">用户中心</el-dropdown-item>
            <el-dropdown-item command="layout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </span>
      </el-dropdown>
    </div>
  </header>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "CommonHeader",
  data() {
    return {
      userImg: require("../assets/images/1.jpeg"),
    };
  },
  methods: {
    handleMenu() {
      this.$store.commit("collapseMenu");
    },
    handleCommand(cmditem){
      if(!cmditem){
        this.$message("菜单缺少command属性");
        return;
      }switch(cmditem){
        case "goTo":
          this.goTo();
          break;
          case "layout":
            this.layout();
            break;
      }

    },
    goTo() {
      this.$router.push('/users')
    },
    layout(){
      
      this.$router.push('/login')
    }
  },
  computed: {
    ...mapState({
      tags: (state) => state.tab.tabsList,
    }),
  },
};
</script>
<style lang="less" scoped>
header {
  display: flex;
  height: 100%;
  justify-content: space-between;
  align-items: center;
}
.l-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
}
.r-content {
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
</style>